package com.jingyuan.biz.server.testnetty;

import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.CharsetUtil;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;

import java.util.List;

public class EventRQDecoder extends MessageToMessageDecoder<ByteBuf> {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        //StringBuilder builder=new StringBuilder();
        if(byteBuf.isReadable()){
            CharSequence sequence = byteBuf.readCharSequence(0,CharsetUtil.UTF_8);
            String str=sequence.toString();
            System.out.println("收到的消息为："+str);
            list.add(JSON.parse(str));
        }

    }

//    @Override
//    protected void encode(ChannelHandlerContext channelHandlerContext, EventRQ eventRQ, ByteBuf byteBuf) throws Exception {
//
//    }
}
